<script setup lang="ts">
  import {ref} from 'vue'
  import { onClickOutside } from '@vueuse/core';

  const {title, modelValue=false} = defineProps<{
    title: string,
    modelValue: boolean
  }>()

  const target = ref(null)
  onClickOutside(target, ()=>{
    hClose()
  })

  const emit = defineEmits<{
    (e: 'update:modelValue', val: boolean): void
  }>()
  const hClose = () => {
    emit('update:modelValue', false)
  }
</script>

<template>
  <div>
    <div class="dailog">
      <div class="wrapper" v-show="modelValue" ref="target">
        <div class="header">
          <h2>{{title}}</h2>
          <a @click="hClose" href="javascript:;" class="iconfont icon-close-new"></a>
        </div>
        <div class="body">
          <!-- 默认插槽 -->
          <slot></slot>
        </div>
        <div class="footer">
          <!-- 具名插槽 -->
          <slot name="footer"></slot> 
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
  .dailog {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 8887;
    background: rgba(0, 0, 0, 0.5);
    .wrapper {
      position: absolute;
      width: 600px;
      top: 50%;
      left: 50%;
      border-radius: 4px;
      transform: translate(-50%,-50%);
      background: #fff;
    }
    .header{
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 80px;
      padding: 0 20px;
      font-size: 18px;
      font-weight: normal;
      border: 1px solid#ccc;
      a{
        width: 20px;
        height: 20px;
        font-size: 24px;
        color: #000;
        &:hover {
          color: rgb(188, 187, 187);
        }
      }
    }
    .body {
      padding: 20px 40px;
      font-size: 18px;
    }
    .footer {
      text-align: center;
      padding: 10px 0 30px 0;
    }
  }
</style>
